public var buttonHandler:ButtonHandler2;
public var ui:UIHandler;
public var aiName:String;
public var aiType:String;

var baseEgoCap:int=100;
var egoModifier=0;
var currentEgo=100;
var baseEgoRegen:int=10;
var startingSize=100;

var teamNum:int;
var slots:Array=new Array();
var slotSpeeds:Array=new Array();

var playerStats:Array=[0,0,0,0,0,0];
var playerStatBuffs:Array=[0,0,0,0,0,0];
var playerStatDebuffs:Array=[0,0,0,0,0,0];
var playerStatPassives:Array=[0,0,0,0,0,0];


var buffTimers:Array=[0,0,0,0,0,0];
var debuffTimers:Array=[0,0,0,0,0,0];


private var consecutiveAttackNum:int;
private var randomGen:Random=new Random();



function NextMove(oppTower:Tower,oppPlayer:PlayerObject,aiTower:Tower){
	if(aiType=="Jack Young"){
		if(ui.GetChargeNum(2,"Passion")==2 && currentEgo>=20){
			buttonHandler.currentButtonSelected="Passion";
		}
		else if(ui.GetChargeNum(2,"Deception")==2 && currentEgo>=60){
			buttonHandler.currentButtonSelected="Deception";
		}
		else if((oppPlayer.currentEgo>parseInt(oppPlayer.baseEgoCap*.75))&& currentEgo>=parseInt(slots[2][3])){
			buttonHandler.currentButtonSelected="23";
		}
		else if((oppTower.height>aiTower.height) && currentEgo>=parseInt(slots[4][3])){
			buttonHandler.currentButtonSelected="25";
		}
		// else if(consecutiveAttackNum>1){
			// check=parseInt((randomGen.value)*100)%3;
			// if(check==2){
				// buttonHandler.currentButtonSelected="24";
			// }
		// }
		else if(currentEgo>=parseInt(slots[0][3])){
			buttonHandler.currentButtonSelected="21";
		}
		else{
			buttonHandler.currentButtonSelected="";
		}
			
	}
	else if(aiType=="Graham Cobb"){
		if(ui.GetChargeNum(2,"Passion")==2 && currentEgo>=20){
			buttonHandler.currentButtonSelected="Passion";
		}
		else if(currentEgo<30){
			buttonHandler.currentButtonSelected="22";
		}
		
		else if(currentEgo>parseInt(slots[0][3])){
			buttonHandler.currentButtonSelected="21";
		}
		else{
			buttonHandler.currentButtonSelected="";
		}
	}
	
	
	
}



function GetStartingSizeBonus(){
	return this.startingSize;
}

function getConsecutiveAttkNum(){
	return consecutiveAttackNum;
}

function setConsecutiveAttkNum(inNum:int){
	consecutiveAttkNum=inNum;
}

function ImportSlots()
{
	var i;
	for(i=1;i<6;i++)
	{
		//Debug.Log("Preparing to import slot "+ i + "for player " +this.teamNum);
		curSlot=this.gameObject.GetComponent("HandHandler").GetAISlot(this.aiType,i);
		Debug.Log(curSlot[8]);
		this.slotSpeeds.Add(curSlot[8]);
		this.slots.Add(curSlot);
		Debug.Log(curSlot);
	}
	//print("Import Slots Complete");
}

function SetupPassive()
{
	var i;
	for(i=5;i<8;i++)
	{
		if (this.slots[i][2] != "Empty")
		{
			var passiveType= this.slots[i][4];
			var passivePower=this.slots[i][5];
			//Debug.Log(passiveType + " " + passivePower);
			
			
			if (passiveType== "Ego Regen Buff")
			{
				this.playerStatPassives[statEnum.EgoRegen]=
					this.playerStatPassives[statEnum.EgoRegen]+passivePower;
			}
			else if (passiveType== "Ego Buff")
			{
				this.playerStatPassives[statEnum.Ego]=
					this.playerStatPassives[statEnum.Ego]+passivePower;
			}
			else if (passiveType== "Speed Buff")
			{
				this.playerStatPassives[statEnum.Speed]=
					this.playerStatPassives[statEnum.Speed]+passivePower;
			}
			else if (passiveType== "Attack Buff")
			{
				this.playerStatPassives[statEnum.Attack]=
					this.playerStatPassives[statEnum.Attack]+passivePower;
			}
			else if (passiveType== "Building Buff")
			{
				this.playerStatPassives[statEnum.Building]=
					this.playerStatPassives[statEnum.Building]+passivePower;
			}
			else if (passiveType== "Starting Size Buff")
			{
				this.playerStatPassives[statEnum.StartingSize]=
					this.playerStatPassives[statEnum.StartingSize]+passivePower;
			}
		}
	}
}

function DecreaseEgo(amount:int)
{
	this.currentEgo=this.currentEgo-amount;
	if (this.currentEgo<0) this.currentEgo=0;
}

function AddEgo(amount:int)
{
	this.currentEgo=this.currentEgo+amount;
	if (this.currentEgo>this.baseEgoCap) this.currentEgo=this.baseEgoCap;
}

function EgoRegen(){
	egoReg=this.baseEgoRegen;
	this.AddEgo(egoReg);
}

function GetHandTypes()
{
	var result=new Array();
	var i;
	for(i=0;i<5;i++)
	{
		curSlot=slots[i];
		curSlotType=curSlot[7];
		result[i]=curSlotType;
	}
	return result;
}
